package com.example.demo.common;

import lombok.Data;

import java.io.Serializable;

/**
 *  统一返回对象
 */
@Data
public class AjaxResult implements Serializable {
        private int code;
        private String msg;
        private Object data;

    /**
     *      返回成功数据
     * @param data
     * @return
     */
    public static AjaxResult success(Object data){
            AjaxResult ajaxResult = new AjaxResult();
            ajaxResult.setCode(200);
            ajaxResult.setMsg("");
            ajaxResult.setData(data);
            return ajaxResult;
        }
    public static AjaxResult success(String msg,Object data){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setCode(200);
        ajaxResult.setMsg(msg);
        ajaxResult.setData(data);
        return ajaxResult;
    }

    /**
     *          返回错误数据
     * @param msg
     * @param
     * @return
     */
    public static AjaxResult fail(Integer code,String msg){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setCode(code);
        ajaxResult.setMsg(msg);
        ajaxResult.setData("");
        return ajaxResult;

    }
    public static AjaxResult fail(String msg,Object data){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setCode(200);
        ajaxResult.setMsg(msg);
        ajaxResult.setData(data);
        return ajaxResult;

    }
    public static AjaxResult fail(Integer code,String msg,Object data){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setCode(code);
        ajaxResult.setMsg(msg);
        ajaxResult.setData(data);
        return ajaxResult;
    }


}


